﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace com.codeplex.eatoutadvocate.Engine
{
    public class Score
    {
        private Score() { /*Should never be initialized*/ }
        # region WEIGHTS

        private const float TIMEWEIGHT = 30;
        private const float MOODWEIGHT = 15;
        private const float MOODLEVELWEIGHT = 15; 
        private const float WEATHERWEIGHT = 15;
        private const float TEMPERATUREWEIGHT = 25;

        private static User user;
        
        # endregion

        private const int CATEGORY_RANGE = 3;

        public static void InitUser(int userTime, Mood userMood, int userMoodLevel, Weather userWeather, Temperature userTemperature)
        {
            user = User.getNewUser();
            user.UserTime = userTime;
            user.UserMood = userMood;
            user.UserMoodLevel = userMoodLevel;
            user.UserWeather = userWeather;
            user.UserTemperature = userTemperature;
        }

        public static float Compute(EatOut eatout)
        {
            float score = 0;
            int timeOffset = Math.Abs(user.UserTime - eatout.Time);                  //In hours
            score += TIMEWEIGHT - (TIMEWEIGHT / 24 * timeOffset);

            if (user.UserMood.Equals(eatout.Mood))
            {   
                score += MOODWEIGHT;
                if (!user.UserMoodLevel.Equals(0) || !user.UserMoodLevel.Equals(null))
                {
                    int moodLevelOffset = Math.Abs(user.UserMoodLevel - eatout.MoodLevel);
                    score += MOODLEVELWEIGHT - (MOODLEVELWEIGHT / CATEGORY_RANGE * moodLevelOffset);
                }
                else
                {
                    score += MOODLEVELWEIGHT;
                }
            }

            if (user.UserWeather.Equals(eatout.Weather))
            {
                score += WEATHERWEIGHT;
            }

            int temperatureOffset = Math.Abs(user.UserTemperature - eatout.Temperature);
            score += TEMPERATUREWEIGHT - (TEMPERATUREWEIGHT / Enum.GetNames(typeof(Temperature)).Length * temperatureOffset);

            //eatout.Score = score;
            
            //return eatout;
            return score;
        }
    }
}
